package com.bluedon.ism.commons.entity;


import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * 账号角色关联表
 */
@Entity
@Table(name = "ACCOUNT_ROLE")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AccountRole implements java.io.Serializable {

	private long arid;
	private Account account;
	private Role role;
	/**
	 * 0-用户，可扩展
	 */
	private Integer type;

	
	public AccountRole() {
    }

    /**
	 * 账号角色 构造函数
	 * @param account
	 * @param role
	 * @param type
	 */
    public AccountRole(Account account, Role role, Integer type) {
        this.account = account;
        this.role = role;
        this.type = type;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
	@Column(name = "ARID", unique = true, nullable = false, precision = 10, scale = 0)
	public long getArid() {
		return this.arid;
	}

	public void setArid(long arid) {
		this.arid = arid;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "AID")
	public Account getAccount() {
		return this.account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "RID", nullable = false)
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

    @Column(name = "TYPE", precision = 1, scale = 0, nullable = false)
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
}
